package com.example.myapplication;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

public class FriendFragment extends Fragment {
    private List<Friend> friendList = new ArrayList<>();


    private void initView(View view){
        RecyclerView recyclerView =  view.findViewById(R.id.friend_recyclerview);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(layoutManager);
        initFriends();
        FriendAdapter adapter = new FriendAdapter(friendList);
        recyclerView.setAdapter(adapter);
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_friend, container, false);
        initView(view);
        return view;
    }
    private void initFriends() {
        for (int i = 0; i < 2; i++) {
            Friend zhangsan = new Friend("张三","爱跳舞爱跳舞爱跳舞爱跳舞", R.drawable.avator01);
            friendList.add(zhangsan);
            Friend lisi = new Friend("李四","爱唱歌爱唱歌爱唱歌爱唱歌", R.drawable.avator02);
            friendList.add(lisi);
            Friend wangwu = new Friend("王五","爱跑步爱跑步爱跑步爱跑步", R.drawable.avator03);
            friendList.add(wangwu);
            Friend zhaoliu = new Friend("赵六","爱淋雨爱淋雨爱淋雨爱淋雨", R.drawable.avator04);
            friendList.add(zhaoliu);
            Friend zhouqi = new Friend("周七","爱走路爱走路爱走路爱走路", R.drawable.avator05);
            friendList.add(zhouqi);
            Friend a = new Friend("李华","不爱唱歌不爱唱歌不爱唱歌", R.drawable.avator06);
            friendList.add(a);
            Friend b = new Friend("刘肆","不爱跳舞不爱跳舞不爱跳舞", R.drawable.avator07);

        }
    }
}